<?php
/**
 * Created by JetBrains NetBeans.
 * User: yinyancai
 * Date: 13-3-14 下午4:44
 * To change this template use File | Settings | File Templates.
 */
if (!defined('IN_MOBILE_API')) {
    exit('Access Denied');
}
include_once 'forum.php';
class cloud_api {
    function common() { }
    //通过传递的参数：应用id,选择的收货地址id,购物车产品ids
    //1、通过收货地址id得到所在的省,
    //2、根据应用id和所在省得到所有的运费标准列表。
    //3、根据产品信息得到产品的重量
    //4、计算出运费的价格
    function output() {
        global $_G;

        if (empty($_GET['caid']) || empty($_GET['csaid'])||empty($_GET['cartids'])) {
            $variable = array(
                'code' => 1001,
                'messagestr' => lang('plugin/cloud', '1001'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }
        $address = C::t('#cloud#cloud_shipping_address')->fetch_info($_GET['csaid']);

        $address_province = $address['province'];

        $express_all  = C::t('#cloud#cloud_express')->fetch_by_province_all($_GET['caid'],$address_province);
        //订单的总重量
        $product_count_weight = 0;
         //查询订单里面的产品信息
        $cartid_array = explode(',', $_GET['cartids']);
        foreach ($cartid_array as $k => $v) {
            //查询购物车上订单产品数据
            $cart = C::t('#cloud#cloud_shopping_cart')->fetch_info($v);
            $product = C::t('#cloud#cloud_product')->fetch_info($cart['cpid']);
            $product_count_weight +=intval($product['weight']) * $cart['pnumber'];
        }


        $return_data=array();
        foreach($express_all as $key=>$value){
            $express_info = array();
            $express_info['title'] = $value['title'];
            //总邮费=首重+续重*数量
            $express_info['examount'] =  intval($value['first_amount']) + intval(intval($value['renewal_amount']) * ceil(($product_count_weight - 1000) / 1000));
            array_push($return_data,$express_info);
        }



        //正常返回
        $variable = array(
            'data'=>$return_data
        );
        cloud_core::result(cloud_core::variable($variable));
    }
}

?>